# GuaNameMapper.py
from constants import GUA_NAME_LST

class GuaNameMapper:
    @staticmethod
    def by_idx(idx: int, which_lst=None) -> str:
        """
        已知Idx，获取卦的全名
        :param idx: 卦的序号
        :param which_lst: 使用的列表，可选值为 'full' 或自定义列表
        :return: 卦的全名
        """
        if idx is None or idx < 0 or idx >= len(GUA_NAME_LST):
            return None

        li = GUA_NAME_LST
        if which_lst == 'full':
            prefixes = '天泽火雷风水山地'
            if idx % 9:
                return prefixes[idx % 8] + prefixes[idx // 8] + li[idx]
            else:
                return li[idx] + '为' + prefixes[idx // 9]
        elif isinstance(which_lst, list):
            li = which_lst
        return li[idx]

    @staticmethod
    def by_name(gua_name: str) -> int | None:
        """
        已知卦名，获取卦的序号
        :param gua_name: 卦名
        :return: 卦的序号
        """
        if gua_name in GUA_NAME_LST:
            return GUA_NAME_LST.index(gua_name)
        return None